package cn.shengongying.admin.controller;

import cn.shengongying.admin.dto.HotCityInDTO;
import cn.shengongying.bean.DataTablePageResult;
import cn.shengongying.bean.ResponseResult;
import cn.shengongying.dubbo.modal.HotCity;
import cn.shengongying.dubbo.service.IHotCityService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * author: RXK
 * date: 2022/2/23 星期三
 * desc:
 */
@Controller
@RequestMapping("/sys/hot/city")
public class HotCityController extends BaseController{

    @DubboReference(version = IHotCityService.version)
    private  IHotCityService hotCityService;

    @RequestMapping("/index")
    public String index() {
        return "/hot_city/index";
    }

    @ResponseBody
    @RequestMapping("/list")
    public DataTablePageResult<List<HotCity>> list(@RequestBody HotCityInDTO inDTO) {
        List<HotCity> list = hotCityService.list();
        inDTO.setData(list);
        long count = hotCityService.count();
        inDTO.setRecordsTotal(count);
        return inDTO;
    }


    @ResponseBody
    @RequestMapping("/save")
    public ResponseResult<String> update(@RequestBody HotCityInDTO inDTO) {
        hotCityService.saveOrUpdate(inDTO.hotCity());
        return ResponseResult.success();
    }


    @ResponseBody
    @RequestMapping("/detail")
    public ResponseResult<HotCity> detail(@RequestBody HotCityInDTO inDTO) {
        HotCity hotCity = hotCityService.getById(inDTO.getId());
        return ResponseResult.success(hotCity);
    }


}
